package Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class DownWebMa {
 public static String downLoadMa(String url,String encoding){
	StringBuffer buffer=new StringBuffer();
	URL downMa=null;
	URLConnection openConn=null;
	InputStreamReader isr=null;
	BufferedReader bur=null;
	
	try {
		//1.建立网络连接
		downMa=new URL(url);
		//2.打开网络连接
		 openConn = downMa.openConnection();
		//3.建立一个传输流
		isr=new InputStreamReader(openConn.getInputStream(),encoding);
		//4.将资源放到缓存中
		bur=new BufferedReader(isr);
		
		String temp=null;
		while((temp=bur.readLine())!=null){
			buffer.append(temp);
		}
		
		
	} catch (MalformedURLException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}finally{
			try {
				isr.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
    return buffer.toString();
 }
	
	
	
	public static void main(String args[]){
		
		String url="http://app.news.baidu.com/?src=pctop";
		String encoding="utf-8";
		String downLoadMa = downLoadMa(url,encoding);
		System.out.println(downLoadMa);
		
	}
	
	
	
	
	
	
	
	

}
